﻿using System;
using System.Collections.Generic;
using System.Text;

namespace iMainAddin
{
    namespace iItem
    {
        public class Variables
        {
            protected delegate String ConvertFunction();
            protected String m_Value;
            protected ConvertFunction m_Convert;

            protected Variables(String setValue)
            {
                m_Value = setValue;
            }
            
            public String Convert()
            {
                return m_Convert();
            }
            
            public String DefaultConvert()
            {
                return m_Value;
            }
            
            public String DataTimeConvert()
            {
                return DateTime.Now.ToString();
            }

            public String MachineConvert()
            {
                if (m_Value == null)
                    return Environment.MachineName;

                return m_Value;
            }

            static public Variables Create(String value)
            {
                return Create("default", value);
            }
            static public Variables Create(String keyName, String value)
            {
                Variables createVariables = new Variables(value);
                switch (keyName)
                {
                    case "$(DataTime)":
                        {
                            createVariables.m_Convert = createVariables.DataTimeConvert;
                        }
                        break;
                    case "$(Name)":
                        {
                            createVariables.m_Convert = createVariables.MachineConvert;
                        }
                        break;
                    default:
                        {
                            createVariables.m_Convert = createVariables.DefaultConvert;
                        }
                        break;
                }
                return createVariables;
            }
        }
    }
}
